#include <iostream>
#include <memory>
#include <unistd.h>
#include "task.hpp"
#include "threadPool.hpp"
int calculate(int a, int b, char op)
{
    int result = 0;
    switch (op)
    {
    case '+':
        result = a + b;
        break;
    case '-':
        result = a - b;
        break;
    case '*':
        result = a * b;
        break;
    case '/':
    {
        if (b == 0)
            std::cerr << "除数不能为0\n";
        else
            result = a / b;
    }
    break;
    case '%':
    {
        if (b == 0)
            std::cerr << "取模的数字不能为0\n";
        else
            result = a % b;
    }
    break;
    default:
        break;
    }
    return result;
}
int main()
{
    srand((uint64_t)time(nullptr));
    std::unique_ptr<threadPool<task>> tp(threadPool<task>::getInstance());
    //tp->init();
    tp->start();
    tp->check();
    /*     threadPool<task>::getInstance()->init();
        threadPool<task>::getInstance()->start();
        threadPool<task>::getInstance()->check(); */
    while (true)
    {
        int x, y;
        char op;
        std::cout << "please Enter x> " << std::endl;
        std::cin >> x;
        std::cout << "please Enter op(+-*/%)> " << std::endl;
        std::cin >> op;
        std::cout << "please Enter y> " << std::endl;
        std::cin >> y;
        task Task(x, y, op, calculate);
        tp->pushTask(Task);
        usleep(1000);
    }
    return 0;
}